package com.xyyl.patient.service.order;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.math.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xyyl.patient.core.constant.AppEnum;
import com.xyyl.patient.core.support.Pager;
import com.xyyl.patient.core.util.DateUtils;
import com.xyyl.patient.entity.order.SpeedPhoneOrder;
import com.xyyl.patient.mapper.order.SpeedPhoneOrderMapper;

/**
 * @projectName:xyyl-patient-service
 * @ClassName: SpeedPhoneOrderServiceImpl
 * @Description: 极速订单业务逻辑实现
 * @author chen
 * @date 2018年1月2日
 *
 */
@Service("speedPhoneOrderService")
public class SpeedPhoneOrderServiceImpl implements SpeedPhoneOrderService {

	@Autowired
	private SpeedPhoneOrderMapper speedPhoneOrderMapper;
	
	

	@Override
	public long insertSpeedPhoneOrder(SpeedPhoneOrder speedPhoneOrder) {
		String preCode = DateUtils.formatDatetime(new Date(), "yyyyMMddHHss") + RandomUtils.nextInt(99999);
		speedPhoneOrder.setOrderSn("JS-" + preCode);
		speedPhoneOrder.setCreateTime(DateUtils.currentDatetime());
		speedPhoneOrder.setExpireTime(DateUtils.addMinute(new Date(), 10));
		return speedPhoneOrderMapper.insert(speedPhoneOrder)==1?speedPhoneOrder.getId():null;
	}

	@Override
	public Map<String,Object>queryInfo(Integer id,Integer type){
		try {
			if(type == 1){
				return speedPhoneOrderMapper.queryInfo1(id);
			}else if(type == 2){
				return speedPhoneOrderMapper.queryInfo2(id);
			}else if(type == 3){
				return speedPhoneOrderMapper.queryInfo3(id);
			}else if(type == 4){
				return speedPhoneOrderMapper.queryInfo4(id);
			}else if(type == 5){
				return speedPhoneOrderMapper.queryInfo5(id);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return  new HashMap<>();
	}

	@Override
	public int confirmPayOrder(SpeedPhoneOrder speedPhoneOrder) {
		speedPhoneOrder.setPayTime(DateUtils.currentDatetime());
		speedPhoneOrder.setStatus(AppEnum.common.Pay_status_confirm.getValue());
		return speedPhoneOrderMapper.update(speedPhoneOrder);

	}

	@Override
	public SpeedPhoneOrder queryObject(Map<String, Object> paramMap) {
		return speedPhoneOrderMapper.queryForObject(paramMap);
	}

	@Override
	public List<SpeedPhoneOrder> queryForList(Pager pager) {
		return speedPhoneOrderMapper.queryForPage(pager);
	}

}
